define(["jquery","bbcare"],function($,$bb){
	var servers = {};
    var URL = $bb.baseUrl("nutrition");

    /**
     * 查询食品库
     */
	servers.ajaxFoodlibraryList = function(callback){
        $bb.ajax({
            url: URL + "nutritiouScheme/service/nutrition/foodlibrary/list",
            success: function(data){
                if(data.success){
                    callback(data.rows);
                }else{
                    $bb.toastShow(data.msg ? data.msg : "查询食品库出错！");
                }
            }
        });
    }

    /**
     * 处理请求到的食品库list信息
     */
    servers.handleFoodLibirayList = function(list){
        for (var i = 0; i < list.length; i++) {
            list[i].createTime = list[i].createTime.substr(0,10);
        }
        return {"list":list};
    }

    /**
     * 获取食品库基本信息（根据食品库id）
     */
    servers.getFoodlibraryInfo = function(data,foodLibraryId){
        for (var i = 0; i < data.length; i++) {
            if( data[i].foodLibraryId == foodLibraryId ){
                return data[i];
            }
        }
    }

    /**
     * 添加/修改食品库
     */
    servers.ajaxFoodlibraryModify = function(params,callback){
        $bb.ajax({
            url: URL + "nutritiouScheme/service/nutrition/foodlibrary/modify",
            data: JSON.stringify({
                data: params
            }),
            success: function(data){
                if(data.success){
                    callback(data.data);
                }else{
                    $bb.toastShow(data.msg ? data.msg : "添加/修改食品库出错！");
                }
            }
        });
    }

	return servers;
});